# 系统随机生产一个1~100的数字，用户有5尺机会猜这个数字
# 1.猜大了提示大了
# 2.猜小了提示小了
# 3.5次以内猜对了提示
# 4.5尺以内猜度了提示，显示数字

from random import randint

class guess_num:

    def __init__(self):
        self.guess_time = 1
        self.right_num = self.generate_num()

    def generate_num(self):
        right_num = randint(1,100)
        return right_num

    def check(self):
        if self.guess_num.isdigit():
            self.guess_num = int(self.guess_num)
            return True

    def guess(self):
        self.guess_num = input(("第%d次猜，猜一个数字:" % self.guess_time))
        if self.check():
            if self.guess_time < 5:    
                self.verify(self.guess_num)
            else:
                print("游戏结束，正确数字是：", self.right_num)
        else:
            print("输入错误，重新输入")
            self.guess()


    def verify(self, guss_num):
        if self.right_num == self.guess_num:
            print("恭喜你，猜对了")
        elif self.right_num < self.guess_num:
            print("猜大了")
            self.guess_time += 1
            self.guess()
        else:
            print("猜小了")
            self.guess_time += 1
            self.guess()



if __name__ == "__main__":
    this_project = guess_num()
    this_project.guess()
        